package com.pachong.android.frameworkbase.customviews.multiviewpager;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;

import java.util.ArrayList;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/6/27
 * 使用时，需要先setFragmentManager;
 * 注意：一定要调用setfragmentmanager方法，然后才会生成内部的adapter
 */
public class MultiViewPager extends ViewPager implements MultiAddable {

    private MultiAdapter mMultiAdapter;
    private FragmentManager mFragmentManager;
    private Context mContext;


    public MultiViewPager(Context context) {
        super(context);
        mContext = context;
    }

    public MultiViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
    }


    @Override
    public void add(Fragment fragment) {
        mMultiAdapter.add(fragment);
    }

    @Override
    public void add(String imageUrl) {
        mMultiAdapter.add(imageUrl);
    }

    @Override
    public void add(ArrayList<String> imageUrls) {
        mMultiAdapter.add(imageUrls);
    }

    @Override
    public void add(String[] fileUrls) {
        mMultiAdapter.add(fileUrls);
    }

    @Override
    public void add(Uri uri) {
        mMultiAdapter.add(uri);
    }

    @Override
    public void add(int drawableResId) {
        mMultiAdapter.add(drawableResId);
    }

    @Override
    public void add(Drawable drawable) {
        mMultiAdapter.add(drawable);
    }

    @Override
    public void add(Bitmap bitmap) {
        mMultiAdapter.add(bitmap);
    }

    @Override
    public void add(View view) {
        mMultiAdapter.add(view);
    }

    public void setFragmentManager(FragmentManager mFragmentManager) {
        this.mFragmentManager = mFragmentManager;
        mMultiAdapter = new MultiAdapter(mFragmentManager, mContext);
        setAdapter(mMultiAdapter);
    }

}
